package com.yungu.swift.autoconfig.lock;

import com.yungu.swift.autoconfig.redis.RedisStringCacheService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : cuixiuyin
 * @date : 2019/9/9
 */
@Configuration
public class LockAutoConfiguration {

    @Value("${zookeeper.host:127.0.0.1:2181}")
    private String zookeeper;

    @Value("${spring.application.name:}")
    private String namespace;

    @Bean
    public ZkLock zkLock() {
        return new ZkLock(zookeeper, namespace);
    }

    @Bean
    @ConditionalOnMissingBean
    public RedisLock redisLock(RedisStringCacheService redisCacheService) {
        return new RedisLock(redisCacheService);
    }


}
